package com.kadron.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.kadron.base.KBase;

@Entity
@Table(name = "k_confirm_key")
public class ConfirmKey extends KBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7445960423983544381L;
	
	private User user;
	private String confirmKey;
	private boolean confirmed;
	
	private ConfirmKey() {
		super();
	}
	
	public ConfirmKey(User user, String confirmKey) {
		this();
		this.user = user;
		this.confirmKey = confirmKey;
	}

	@ManyToOne(targetEntity = User.class)
	@JoinColumn(name = "user_id", nullable = false, updatable = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	@Column(name = "confirm_key", nullable = false, updatable = false)
	public String getConfirmKey() {
		return confirmKey;
	}

	public void setConfirmKey(String confirmKey) {
		this.confirmKey = confirmKey;
	}

	@Column(name = "confirmed", nullable = false)
	public boolean isConfirmed() {
		return confirmed;
	}

	public void setConfirmed(boolean confirmed) {
		this.confirmed = confirmed;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + (int) (getId() ^ (getId() >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ConfirmKey other = (ConfirmKey) obj;
		if (getId() != other.getId())
			return false;
		return true;
	}
}